import {
	DrbarActionType,
	ICtrlDataAction,
	ICtrlEvent,
	IDrbarAbility,
	IDrbarControllerParams,
	IDrbarModel,
	IDrbarStore,
	IParam,
} from '@/core';
import { QXEvent } from 'qx-util';
import { PropType } from 'vue';
import {
	getCtrlClassNames,
	useCtrlAction,
	useCtrlBasic,
	useCtrlControllerParams,
	useCtrlProps,
} from '../use-ctrl';

/**
 * 关系数据栏输入参数
 *
 * @export
 * @return {*}
 */
export function useDrbarProps() {
	return {
		...useCtrlProps(),
		openView: Function,
        newView: Function,
        actions: Object as PropType<ICtrlDataAction>,
	};
}

/**
 * 关系数据栏基础参数
 *
 * @export
 * @param {IDrbarModel} model
 * @param {IParam} props
 * @return {*}
 */
export function useDrbarBasic(model: IDrbarModel, props: IParam) {
	const getClassNames = (props: IParam) => {
		return getCtrlClassNames(model, props);
	};
	return {
		...useCtrlBasic(model, props),
		getClassNames,
	};
}

/**
 * 关系数据栏部件行为
 *
 * @export
 */
export function useDrbarAction(controller: any) {
    const handleSelectChange = (item: IParam) => {
        controller.handleSelectChange(item);
      }
	return {
		...useCtrlAction(controller),
        handleSelectChange
	};
}

/**
 * 关系数据栏部件控制器
 *
 * @export
 */
export function useDrbarControllerParams<
	S extends IDrbarStore,
	M extends IDrbarModel
>(
	model: M,
	props: any,
	evt: QXEvent<ICtrlEvent<DrbarActionType, IDrbarAbility>>,
    otherParams: IParam = {},
): IDrbarControllerParams<DrbarActionType, IDrbarAbility> {
	return {
		...useCtrlControllerParams<S, M>(model, props, evt, otherParams),
        actions: props.actions,
        openView: props.openView,
		newView: props.newView,
	};
}
